package de.boldt.neanda.engine.core;

import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JFrame;

public class Window extends JFrame implements Actionable, KeyListener
{
	public static int nexusX = 10000;
	public static int nexusY = 10000;
	
	public static int viewX = nexusX / 2;
	public static int viewY = nexusY / 2;
	
	Universum universum = new Universum();
	
	boolean esc = false;
	boolean camLeft = false;
	boolean camRight = false;
	boolean camUp = false;
	boolean camDown = false;
	
	public Window()
	{
		this.setTitle("Neanda Engine by Boldt (C)");
		this.setLayout(null);
		this.setLocation(0, 0);
		
		this.setAlwaysOnTop(true);
		this.setUndecorated(true);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setResizable(false);
		this.setSize(Toolkit.getDefaultToolkit().getScreenSize());
		
		this.addKeyListener(this);
		this.add(universum);
		
		this.setVisible(true);
	}
	
	@Override
	public void action()
	{
		checkKey();
		universum.repaint();
	}

	private void checkKey()
	{
		if(esc)
		{
			System.exit(0);
		}
		if(camLeft)
		{
			universum.setLocation(universum.getLocation().x + 10, universum.getLocation().y);
			Window.viewX -= 10;
		}
		if(camRight)
		{
			universum.setLocation(universum.getLocation().x - 10, universum.getLocation().y);
			Window.viewX += 10;
		}
		if(camUp)
		{
			universum.setLocation(universum.getLocation().x, universum.getLocation().y + 10);
			Window.viewY -= 10;
		}
		if(camDown)
		{
			universum.setLocation(universum.getLocation().x, universum.getLocation().y - 10);
			Window.viewY += 10;
		}
		
	}
	
	@Override
	public void keyPressed(KeyEvent e)
	{
		if(e.getKeyCode() == KeyEvent.VK_ESCAPE)
		{
			esc = true;
		}
		if(e.getKeyCode() == KeyEvent.VK_LEFT)
		{
			camLeft = true;
		}
		if(e.getKeyCode() == KeyEvent.VK_RIGHT)
		{
			camRight = true;
		}
		if(e.getKeyCode() == KeyEvent.VK_UP)
		{
			camUp = true;
		}
		if(e.getKeyCode() == KeyEvent.VK_DOWN)
		{
			camDown = true;
		}
	}

	@Override
	public void keyReleased(KeyEvent e)
	{
		if(e.getKeyCode() == KeyEvent.VK_ESCAPE)
		{
			esc = false;
		}
		if(e.getKeyCode() == KeyEvent.VK_LEFT)
		{
			camLeft = false;
		}
		if(e.getKeyCode() == KeyEvent.VK_RIGHT)
		{
			camRight = false;
		}
		if(e.getKeyCode() == KeyEvent.VK_UP)
		{
			camUp = false;
		}
		if(e.getKeyCode() == KeyEvent.VK_DOWN)
		{
			camDown = false;
		}
	}

	@Override
	public void keyTyped(KeyEvent e)
	{
		;
	}
}
